package com.wd.live.view.fragment

/**
 * 作者：马海钊
 * 时间：2023/9/4 15:44
 * 功能：
 */
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.ImageUtils
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.UriUtils
import com.bumptech.glide.Glide
import com.wd.live.R
import com.wd.live.databinding.FragmentMeBinding
import com.wd.live.model.base.BaseFragment
import com.wd.live.model.base.BaseViewModel
import com.wd.live.model.bean.LocalData
import com.wd.live.model.tool.LoginHelper
import com.wd.live.wxapi.UserInfo
import java.io.File

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * 作者：马海钊
 * 时间：2023年8月18日16:00:52
 * 功能：我的
 */
class MyFragment : BaseFragment<BaseViewModel,FragmentMeBinding>() {
    // TODO: Rename and change types of parameters
    private var param1: String? = null
    private var param2: String? = null
    private var file:File?=null
    override fun initData() {
        var meBean=context?.let {
            LoginHelper.getPersonData(it)
        }
        if (meBean!=null){
            binding.myNameid.setText(meBean?.name)
        }

        Glide.with(this)
            .load(meBean?.img)
            .into(binding.myHeadImgid)
        //换头像
        binding.myHeadImgid.setOnClickListener {
            val intent = Intent(Intent.ACTION_PICK).setType("image/*")
            startActivityForResult(intent,1)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode==1&&data!=null){
            file=UriUtils.uri2File(data.data)
            val bitmap:Bitmap = ImageUtils.getBitmap(file)
            binding!!.myHeadImgid.setImageBitmap(bitmap)
        }
    }
    override fun getViewBinding()=FragmentMeBinding.inflate(layoutInflater)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }


    companion object {
        /**
         * Use this factory method to create a new instance of
         * this fragment using the provided parameters.
         *
         * @param param1 Parameter 1.
         * @param param2 Parameter 2.
         * @return A new instance of fragment MeFragment.
         */
        // TODO: Rename and change types and number of parameters
        @JvmStatic
        fun newInstance() =
            MyFragment().apply {
                arguments = Bundle().apply {

                }
            }
    }
}